package com.qyhl.shop.shop.center.coupon;

import com.qyhl.shop.common.ShopUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.shop.ShopCenterCouponBean;

import java.util.List;

public class ShopCenterCouponListModel implements ShopCenterCouponListContract.ShopCenterCouponListModel {
    private ShopCenterCouponListPresenter mPresenter;

    public ShopCenterCouponListModel(ShopCenterCouponListPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getList(int type, int page, String phoneNum) {
        String url;
        switch (type) {
            case 2:
                url = ShopUrl.SHOP_CENTER_COUPON_USED;
                break;
            case 3:
                url = ShopUrl.SHOP_CENTER_COUPON_EXCEED;
                break;
            default:
                url = ShopUrl.SHOP_CENTER_COUPON;
                break;
        }
        EasyHttp.post(url)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("phoneNum", phoneNum)
                .params("page", page + "")
                .execute(new SimpleCallBack<List<ShopCenterCouponBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.setError("获取优惠券列表失败！");
                    }

                    @Override
                    public void onSuccess(List<ShopCenterCouponBean> beanList) {
                        mPresenter.setList(beanList);
                    }
                });
    }
}
